package com.nineclock.system.controller;

import com.nineclock.common.entity.Result;
import com.nineclock.system.dto.SysCompanyUserDTO;
import com.nineclock.system.service.SysCompanyUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("companyUser")
@Api(value = "员工管理接口", tags = "系统服务")
public class SysCompanyUserController {

    @Autowired
    private SysCompanyUserService companyUserService;

    /**
     * 根据用户id、公司id查询员工列表
     * @return
     */
    @ApiOperation("根据用户id、公司id查询员工列表")
    @GetMapping("query")
    public Result<List<SysCompanyUserDTO>> queryCompanyUser(@RequestParam Long userId,
                                                            @RequestParam(required = false) Long companyId){
        List<SysCompanyUserDTO> companyUserDTOList = companyUserService.queryCompanyUser(userId, companyId);

        return Result.success(companyUserDTOList);
    }

    /**
     * 根据员工id查询员工信息
     */
    @ApiOperation("根据员工id查询员工信息")
    @GetMapping("/query/{companyUserId}")
    public Result<SysCompanyUserDTO> queryCompanyUserById(@PathVariable Long companyUserId){
        SysCompanyUserDTO companyUserDTO = companyUserService.queryCompanyUserById(companyUserId);
        return Result.success(companyUserDTO);
    }

    /**
     * 查询当前企业所有员工
     * @return
     */
    @ApiOperation(value = "查询当前企业所有的员工")
    @GetMapping("/queryAllUser")
    public Result<List<SysCompanyUserDTO>> queryAllCompanyUser(){
        List<SysCompanyUserDTO> companyUserDTOList = companyUserService.queryAllCompanyUser();
        return Result.success(companyUserDTOList);
    }

    /**
     * 组织架构:APP-根据手机号获取员工信息
     * 接口路径：GET/sys/companyUser/queryone
     */
    @GetMapping("queryone")
    @ApiOperation("组织架构:APP-根据手机号获取员工信息")
    public Result<SysCompanyUserDTO> queryone(String mobile){
        SysCompanyUserDTO companyUserDTO = companyUserService.queryOne(mobile);
        return Result.success(companyUserDTO);
    }

    /**
     * 根据企业id获取企业的员工列表
     */
    @ApiOperation(value="查询某企业的员工列表")
    @GetMapping("/queryAllUserByCompanyId")
    public Result<List<SysCompanyUserDTO>> queryAllUserByCompanyId(@RequestParam Long companyId){
        List<SysCompanyUserDTO> companyUserDTOList = companyUserService.queryAllUserByCompanyId(companyId);
        return Result.success(companyUserDTOList);
    }

    /**
     * 根据企业ID查询企业的主管理员
     * @param companyId
     * @return
     */
    @ApiOperation(value="根据企业ID查询企业的主管理员")
    @GetMapping("/queryAdminByCompanyId")
    public Result<SysCompanyUserDTO> queryAdminByCompanyId(@RequestParam Long companyId){
        SysCompanyUserDTO companyUserDTO = companyUserService.queryAdminByCompanyId(companyId);
        return Result.success(companyUserDTO);
    }
}
